
package org.extremecomponents.table.tag;

import org.extremecomponents.table.bean.Column;
import org.extremecomponents.table.core.EccnTableConstants;
import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.table.tag.ColumnTag;
import org.extremecomponents.table.tag.TagUtils;

import javax.servlet.jsp.jstl.fmt.LocaleSupport;

/**
 * @author guanhw
 */
public class EccnColumnTag extends ColumnTag {
	private static final long serialVersionUID = 6125344604305409578L;
	private String highlightClass;
    private String highlight;
    private String onclick;
    private String onmouseout;
    private String onmouseover;
    
    private String bundle;    
    
    
    public void setBundle(String bundle) {    
        this.bundle = bundle;    
    }    


    public void setHighlightClass(String highlightClass) {
        this.highlightClass = highlightClass;
    }


    public void setHighlight(String showHighlight) {
        this.highlight = showHighlight;
    }
    

    public void setOnclick(String onclick) {
        this.onclick = onclick;
    }


    public void setOnmouseout(String onmouseout) {
        this.onmouseout = onmouseout;
    }


    public String getBundle ( ) {
		return bundle;
	}


	public void setOnmouseover(String onmouseover) {
        this.onmouseover = onmouseover;
    }
    
    public void addColumnAttributes( TableModel model , Column column ) {
    	column.addAttribute(EccnTableConstants.HIGHLIGHT_CLASS, TagUtils
				.evaluateExpressionAsString(EccnTableConstants.HIGHLIGHT_CLASS,
						this.highlightClass, this, pageContext));
    	column.addAttribute(EccnTableConstants.HIGHLIGHT, TagUtils
				.evaluateExpressionAsString(EccnTableConstants.HIGHLIGHT,
						this.highlight, this, pageContext));
    	column.addAttribute(EccnTableConstants.ON_CLICK, TagUtils
				.evaluateExpressionAsString(EccnTableConstants.ON_CLICK,
						this.onclick, this, pageContext));
    	column.addAttribute(EccnTableConstants.ON_MOUSE_OUT, TagUtils
				.evaluateExpressionAsString(EccnTableConstants.ON_MOUSE_OUT,
						this.onmouseout, this, pageContext));
    	column.addAttribute(EccnTableConstants.ON_MOUSE_OVER, TagUtils
				.evaluateExpressionAsString(EccnTableConstants.ON_MOUSE_OVER,
						this.onmouseover, this, pageContext));
    	
    	
    	//
    	if ( bundle != null && !"".equals ( bundle )) {
    		String titleValue = column.getTitle();    
    		String value = LocaleSupport.getLocalizedMessage ( pageContext , titleValue  , bundle ) ;
    		if ( value != null ) column.setTitle ( value  ) ; 
    	}
    }
    
    public void modifyColumnAttributes(TableModel model, Column column) {
    	column.addAttribute(EccnTableConstants.HIGHLIGHT_CLASS, TagUtils
				.evaluateExpressionAsString(EccnTableConstants.HIGHLIGHT_CLASS,
						this.highlightClass, this, pageContext));
    	column.addAttribute(EccnTableConstants.HIGHLIGHT, TagUtils
				.evaluateExpressionAsString(EccnTableConstants.HIGHLIGHT,
						this.highlight, this, pageContext));
    	column.addAttribute(EccnTableConstants.ON_CLICK, TagUtils
				.evaluateExpressionAsString(EccnTableConstants.ON_CLICK,
						this.onclick, this, pageContext));
    	column.addAttribute(EccnTableConstants.ON_MOUSE_OUT, TagUtils
				.evaluateExpressionAsString(EccnTableConstants.ON_MOUSE_OUT,
						this.onmouseout, this, pageContext));
    	column.addAttribute(EccnTableConstants.ON_MOUSE_OVER, TagUtils
				.evaluateExpressionAsString(EccnTableConstants.ON_MOUSE_OVER,
						this.onmouseover, this, pageContext));
    	
    	if ( bundle != null && !"".equals ( bundle )) {
    		String titleValue = column.getTitle();    
    		String value = LocaleSupport.getLocalizedMessage ( pageContext , titleValue  , bundle ) ;
    		if ( value != null ) column.setTitle ( value  ) ; 
    	}    	
    }


    public void release()
    {
        super.release();
        highlightClass = null;
        highlight = null;
        onclick = null;
        onmouseout = null;
        onmouseover = null;
        this.bundle = null ;
    }
	
}
